package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/gorilla/mux"
)

//var HTTPConfigWriter *http.ResponseWriter

func HTTPServerRun() {
	router := mux.NewRouter().StrictSlash(true)
	router.HandleFunc("/", routerIndex)
	router.HandleFunc("/p", routerHTTPDataWork)
	log.Fatal(http.ListenAndServe(":"+SY.HTTPPort, router))
}

func routerIndex(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusOK)
	fmt.Fprint(w, "1\n")
	//testJsonForm(w, r)
}

func routerHTTPDataWork(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusOK)
	httpMessageDoWork(w, r)
	//u := Message{P: "liamPost222", D: "123", O: "time.Now()", I: "asd1234"}
	//httpMessageSendToClient(u, w)
}

// func httpMessageSendBackClient(d Message) {
// 	u := Message{P: "liamPost", D: "123", O: "time.Now()", I: "asd1234"}
// 	MyPrintf("\n httpMessageSendBackClient back: %s \n", d)
// 	if err := json.NewEncoder(*HTTPConfigWriter).Encode(u); err != nil {
// 		panic(err)
// 	}
// 	MyPrintf("\n httpMessageSendBackClient back: end \n")
// }
